<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/Public/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/Public/style/admin.css" media="all">
  <link id="layuicss-layer" rel="stylesheet"
    href="https://www.layui.com/admin/std/dist/layuiadmin/layui/css/modules/layer/default/layer.css?v=3.1.1"
    media="all">

  <style>
    .layui-upload-img {
      width: 92px;
      height: 92px;
      margin: 0 10px 10px 0;
    }
  </style>
</head>

<body>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">文件上传(七牛云SDK)</div>
          <div class="layui-card-body">
            <div class="layui-upload">
              <button type="button" class="layui-btn" id="upload">上传图片</button>
              <div class="layui-upload-list">
                <img class="layui-upload-img" id="img">
                <p id="links"></p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>


  <script src="/Public/layui/layui.js"></script>
  <script>
    layui.config({
      base: '/Public/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use('upload', function () {
      var $ = layui.$
        , upload = layui.upload;

      //普通图片上传
      var uploadInst = upload.render({
        elem: '#upload'
        , url: '/Admin/Upload/uploadApi?project=rbac' //改成您自己的上传接口
        , before: function (obj) {
          //预读本地文件示例，不支持ie8
          obj.preview(function (index, file, result) {
            $('#img').attr('src', result); //图片链接（base64）
          });
        }
        , done: function (res) {
          //如果上传失败
          if (res.code == 0) {
            return layer.msg('上传失败');
          } else {
            var links = $('#links');
            links.html('<span>上传成功，外链地址是：' + res.data + '</span>');
          }
          //上传成功
        }
      });

    });
  </script>
</body>

</html>